package com.service.impl;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import com.dto.User;
import com.jpa.UserRepository;
import com.mapper.UserMapper;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author HuangSuip
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserRepository userRepository;

    @Override
    public String getName() {
        Map map = new HashMap();
        map.put("name", "HuangSuip");
        return userMapper.getUserName(map);
    }

    @Override
    @Transactional
    public int insert(User user) {
        user = userRepository.save(user);
        user.setName(user.getName() + "HuangSuip");
        if (true){
            //throw new RuntimeException();
        }
        return userMapper.updateUser(user);
    }


    @PostConstruct
    public void construct() {
        LOGGER.info(String.valueOf(userMapper));
    }


}
